package com.yuke.cloud.service.uac.service;

import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.base.dto.LoginAuthDto;
import com.yuke.cloud.common.core.support.IService;
import com.yuke.cloud.common.security.core.SecurityUser;
import com.yuke.cloud.service.api.uac.dto.WarehouseAdminUserDto;
import com.yuke.cloud.service.uac.dto.*;
import com.yuke.cloud.service.uac.entity.AccUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;

/**
 * Created by wg on 2018/09/11.
 */
public interface AccUserService extends IService<AccUser> {

    /**
     * 根据登录名查询用户信息
     *
     * @param loginName the login name
     *
     * @return the uac user
     */
    AccUser findByLoginName(String loginName);

    /**
     * 根据用户ID查询用户信息.
     *
     * @param userId the user id
     *
     * @return the uac user
     */
    AccUser findUserInfoByUserId(Long userId);

    /**
     * 根据用户openId查询用户信息.
     *
     * @param openId
     *
     * @return the uac user
     */
    AccUser findByOpenId(String openId);

    /**
     * 更新用户信息
     *
     * @param accUser the uac user
     *
     * @return the int
     */
    int updateUser(AccUser accUser);

    /**
     * 获取用户拥有的所有权限编码.
     *
     * @param userId the user id
     *
     * @return the collection
     */
    Collection<GrantedAuthority> loadUserAuthorities(Long userId);

    /**
     * Handler login data.
     *
     * @param token     the token
     * @param principal the principal
     * @param request   the request
     */
    void handlerLoginData(OAuth2AccessToken token, final SecurityUser principal, final HttpServletRequest request);

    /**
     * Find user info by login name uac user. todo:这个不会根据组ID来判断
     *
     * @param loginName the login name
     *
     * @return the uac user
     */
    AccUser findUserInfoByLoginName(String loginName);

    /**
     * 根据手机号查询用户信息.
     *
     * @param mobileNo the mobile no
     *
     * @return the acc user
     */
    AccUser findByMobileNo(String mobileNo);

    /**
     * 校验登录名是否存在.
     *
     * @param loginName the login name
     *
     * @return the boolean
     */
    boolean checkLoginName(String loginName);

    /**
     * 校验邮箱是否存在.
     *
     * @param loginName the login name
     *
     * @return the boolean
     */
    boolean checkEmail(String loginName);

    /**
     * 校验手机号是否存在.
     *
     * @param validValue the valid value
     *
     * @return the boolean
     */
    boolean checkMobileNo(String validValue);

    /**
     * 重置登录密码.
     *
     * @param userId       the user id
     * @param loginAuthDto the login auth dto
     */
    void resetLoginPwd(Long userId, LoginAuthDto loginAuthDto);

    /**
     * 重置登录密码.
     *
     * @param resetLoginPwdDto the reset login pwd dto
     */
    void resetLoginPwd(ResetLoginPwdDto resetLoginPwdDto);

    /**
     * 根据用户ID查询用户信息.
     *
     * @param userId the user id
     *
     * @return the uac user
     */
    AccUser queryByUserId(Long userId);

    /**
     * 注册用户.
     *
     * @param registerDto the register dto
     */
    void register(UserRegisterDto registerDto);
    /**
     * 注册员工用户.
     *
     * @param registerDto the register dto
     */
    void registerEmployee(UserRegisterDto registerDto);
    /**
     * 激活用户.
     *
     * @param activeUserToken the active user token
     */
    void activeUser(String activeUserToken);

    /**
     * 根据组织ID和仓库管理员的角色ID查找与组织关联仓库的管理员
     * @param groupId
     * @param roleId
     * @return
     */
    List<WarehouseAdminUserDto> findWarehousAdminsByGroupId(Long groupId, Long roleId);

    int updateIsEmployeeByIds(List<Long> userIds, Boolean isEmployee);

    /**
     * 修改用户类型
     */
    void modifyUserTypeByIds(List<Long> userIds, Long groupType, Boolean status);

    /**
     * Query user list with page list.
     *
     * @param accUser the uac user
     *
     * @return the list
     */
    PageInfo queryUserListWithPage(AccUser accUser);

    /**
     * 根据用户ID修改用户状态.
     *
     * @param accUser      the uac user
     * @param loginAuthDto the login auth dto
     *
     * @return the int
     */
    int modifyUserStatusById(AccUser accUser, LoginAuthDto loginAuthDto);

    /**
     * 保存用户.
     *
     * @param user         the user
     * @param loginAuthDto the login auth dto
     */
    void saveAccUser(AccUser user, LoginAuthDto loginAuthDto);

    /**
     * 用户修改密码
     *
     * @param userModifyPwdDto the user modify pwd dto
     * @param authResDto       the auth res dto
     *
     * @return the int
     */
    int userModifyPwd(UserModifyPwdDto userModifyPwdDto, LoginAuthDto authResDto);
    int  userModifyPayPwd(UserModifyPwdDto userModifyPwdDto, LoginAuthDto authResDto);
    int userModifyMobileNo(ModifyUserMobile modifyUserMobile, LoginAuthDto authResDto);

    List<AccUser> findUserInfoByUserIds(List<Long> userIds);

    int userModifyPwdByPhone(UserModifyPwdByPhoneDto userModifyPwdByPhoneDto);

    void modifyUserTypeToSellerOrSupplier(Long userId, Integer userType, Boolean isSet);

    List<AccUser> GetUserListByShop(Long shopId, String loginName, String userName, String mobile);

    List<AccUser> selectUserInfoByGroupId(Long groupId);

    List<AccUser> getFindByLoginName(String loginName);

    List<AccUser> getUserPageByUserIds(List<Long> userIds,Byte userType);


    Integer autoRegisterUserAndShop(UserRegisterDto userRegisterDto, String shopName, Long wareHouseId);

    Long autoRegisterUser(UserRegisterDto userRegisterDto);
}
